using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SimpleControl
{
    [ToolboxData("<{0}:MSButton runat='server' strText='Problems?'><{0}:MSButton>")]
    public class MSButton : WebControl
    {
        [
        Category("Appearance"), 
        DefaultValue("Problems?"), 
        Description("Text for Label"),
        Localizable(true),
        PersistenceMode(PersistenceMode.InnerDefaultProperty)]
        public virtual string strText
        {
            get
            {
                string strText = (string)ViewState["strText"];
                if (strText == null)
                    return String.Empty;
                else
                    return strText;
            }
            set
            {
                ViewState["strText"] = value;
            }
        }
        
        protected override void CreateChildControls()
        {
            ClientScriptManager cs = Page.ClientScript;
            Type rsType = this.GetType();

            Literal ltTableStart = new Literal();
            ltTableStart.Text = "<table cellspacing='0' cellpadding='0'><tr><td valign='middle'>";
            this.Controls.Add(ltTableStart);

       
            HyperLink hlHelpFile = new HyperLink();
            hlHelpFile.NavigateUrl = cs.GetWebResourceUrl(rsType, "SimpleControl.Help.htm");
            hlHelpFile.Attributes.Add("onmouseover", "ChangeImage('image1','Red')");
            hlHelpFile.Attributes.Add("onmouseout", "RollbackImage('image1','Green')");
            
            this.Controls.Add(hlHelpFile);

            Image imgTest = new Image();
            imgTest.ImageUrl = cs.GetWebResourceUrl(rsType, "SimpleControl.smallFail.gif");
            imgTest.ID = "image1";
            hlHelpFile.Controls.Add(imgTest);

            Literal ltTableColumn = new Literal();
            ltTableColumn.Text = "</td><td valign='middle'>";
            this.Controls.Add(ltTableColumn);
            
            HyperLink hlHelpFile1 = new HyperLink();
            hlHelpFile1.NavigateUrl = cs.GetWebResourceUrl(rsType, "SimpleControl.Help.htm");
            hlHelpFile1.Attributes.Add("onmouseover", "ChangeImage('image1','Red')");
            hlHelpFile1.Attributes.Add("onmouseout", "RollbackImage('image1','Green')");
            
            this.Controls.Add(hlHelpFile1);

            Label lblHome = new Label();
            lblHome.ID = "Label1";
            lblHome.Text = strText;
            lblHome.Font.Name = "Verdana";
            lblHome.Font.Bold = true;
            lblHome.Font.Size = FontUnit.Medium;
            lblHome.ForeColor = System.Drawing.Color.Green;
            hlHelpFile1.Controls.Add(lblHome);

            Literal ltTableEnding = new Literal();
            ltTableEnding.Text = "</td></tr></table>";
            this.Controls.Add(ltTableEnding);

            cs.RegisterClientScriptInclude("MyScript", cs.GetWebResourceUrl(rsType, "SimpleControl.MyScript.js"));

            base.CreateChildControls();
        }

       
    }
}
